#define _CRT_SECURE_NO_WARNINGS 1

class Allocator {
public:
    Allocator(int n)
        : _n(n)
    {
        _memory = vector<int>(n);
    }

    int allocate(int size, int mID) {
        int free = 0;
        for (int i = 0; i < _n; i++)
        {
            if (_memory[i] == 0)
            {
                if (++free >= size)
                {
                    for (int cur = 0; cur < size; cur++)
                    {
                        _memory[i - cur] = mID;
                    }
                    return i - size + 1;
                }
            }
            else
                free = 0;
        }
        return -1;
    }

    int freeMemory(int mID) {
        int del = 0;
        for (auto& e : _memory)
        {
            if (e == mID)
            {
                e = 0;
                ++del;
            }
        }
        return del;
    }
private:
    vector<int> _memory;
    int _n;
};

/**
 * Your Allocator object will be instantiated and called as such:
 * Allocator* obj = new Allocator(n);
 * int param_1 = obj->allocate(size,mID);
 * int param_2 = obj->freeMemory(mID);
 */